package top.jandmla.imagetest.controller;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.jandmla.imagetest.service.ImageService;
import top.jandmla.imagetest.utils.ResponseResult;

/**
 * <p>
 * 图片上传控制器
 * </p>
 */
@Api("图片上传接口")
@ApiResponses({
        @ApiResponse(code = 200, message = "请求成功！"),
        @ApiResponse(code = 204, message = "请求成功，但是没有数据返回！"),
        @ApiResponse(code = 400, message = "请求失败，参数不对！"),
        @ApiResponse(code = 401, message = "没有登录认证，请认证后在来！"),
        @ApiResponse(code = 403, message = "请求用户的权限不够！"),
        @ApiResponse(code = 404, message = "请求路径不对，请检查后在尝试！"),
})
@RestController
public class ImageController {

    @Autowired
    ImageService service;

    /**
     * 图片上传
     * @param files 图片文件
     * @return 上传结果
     */
    @PostMapping(value = "/upload")
    @ApiOperation(
            value = "文件上传"
            , notes = "上传文件"
            , httpMethod = "POST"
            , produces = "FORM-DATA"
            , protocols = "http"
    )
    @ApiImplicitParams({@ApiImplicitParam(name = "files",example = "1.jpg",allowMultiple = true,value = "上传的图片文件",paramType = "formData",dataType = "file")})
    public ResponseResult uploadImageFile(@RequestPart("files")MultipartFile files){
        return service.uploadImageFile(files);
    }

    /**
     * 参数测试上传
     * @param name 上传参数
     * @return 上传结果
     */
    @PostMapping(value = "/paramTest")
    @ApiOperation(
            value = "文件上传"
            , notes = "上传文件"
            , httpMethod = "POST"
            , protocols = "http"
    )
    @ApiImplicitParams({@ApiImplicitParam(name = "name",example = "参数样例",allowMultiple = true,value = "参数介绍")})
    public ResponseResult paramTest(@RequestBody String name){
        return ResponseResult.success(name);
    }
}
